package com.jeff.android.lab.jframework.app;

import android.app.Application;
import android.content.IntentFilter;

/**
 * @author: duff
 * @date: 2019/1/14
 * @since: 1.0.0
 */
public class BaseApplication extends Application {
    private NetworkChangeReceiver mNetworkChangeReceiver;

    @Override
    public void onCreate() {
        super.onCreate();
        addReceiver();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }

    private void addReceiver() {
        mNetworkChangeReceiver = new NetworkChangeReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        registerReceiver(mNetworkChangeReceiver, filter);
    }

    public void addNetworkChangeListener(NetworkChangeListener l) {
        if (mNetworkChangeReceiver != null)
            mNetworkChangeReceiver.addListener(l);
    }

    public void removeNetworkChangeListener(NetworkChangeListener l) {
        if (mNetworkChangeReceiver != null)
            mNetworkChangeReceiver.removeListener(l);
    }

}
